package com.zrrd.jt_admin.shop.type.controller;


import com.zrrd.jt_admin.common.dto.StatusDto;
import com.zrrd.jt_admin.common.entity.GoodsType;
import com.zrrd.jt_admin.common.page.GoodsTypePageVo;
import com.zrrd.jt_admin.common.response.ResponseResult;
import com.zrrd.jt_admin.shop.type.service.GoodsTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wanjl
 * @since 2024-06-29
 */
@RestController
@RequestMapping("/admin/goodsType")
@ResponseBody
public class GoodsTypeController {

    @Resource
    private GoodsTypeService goodsTypeService;

    @GetMapping("/{page}")
    public ResponseResult findByPage(@PathVariable("page") Integer page, @RequestParam(value = "limit",required = false,defaultValue = "10") Integer limit) {
        GoodsTypePageVo goodsTypePageVo=goodsTypeService.findByPage(page,limit);
        return ResponseResult.queryResponse(goodsTypePageVo);
    }



    @ApiOperation(value = "修改状态", notes = "根据id修改状态")
    @PutMapping("/{id}/updateStatus")
    @ResponseBody
    public ResponseResult setStatus(@PathVariable("id") Integer id,@RequestBody StatusDto statusDto) {
        Boolean bStatus=statusDto.getStatus()==1?false:true;

        boolean flag = goodsTypeService.lambdaUpdate()//使用lambda形式的修改
                .eq(GoodsType::getId, id) //比较id
                .set(GoodsType::getStatus, bStatus)//进行修改
                .update();//执行修改
        return ResponseResult.updateResponse(flag);
    }
}

